package comgutianyu.qihangjiaoyu.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "qihang.db";
    private static final int DATABASE_VERSION = 2;

    // 用户表
    public static final String TABLE_USERS = "users";
    public static final String COLUMN_ID = "id";
    public static final String COLUMN_NICKNAME = "nickname";
    public static final String COLUMN_USERNAME = "username";
    public static final String COLUMN_PHONE = "phone";
    public static final String COLUMN_GENDER = "gender";
    public static final String COLUMN_EXAM_INTENTION = "exam_intention";
    public static final String COLUMN_AVATAR_PATH = "avatar_path";
    public static final String COLUMN_PASSWORD = "password";

    // 创建用户表的SQL语句
    private static final String CREATE_TABLE_USERS = 
            "CREATE TABLE " + TABLE_USERS + " (" +
                    COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                    COLUMN_NICKNAME + " TEXT, " +
                    COLUMN_USERNAME + " TEXT UNIQUE, " +
                    COLUMN_PHONE + " TEXT, " +
                    COLUMN_PASSWORD + " TEXT, " +
                    COLUMN_GENDER + " TEXT, " +
                    COLUMN_EXAM_INTENTION + " TEXT, " +
                    COLUMN_AVATAR_PATH + " TEXT" +
                    ")";

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // 创建用户表
        db.execSQL(CREATE_TABLE_USERS);
        
        // 插入管理员用户数据
        ContentValues adminValues = new ContentValues();
        adminValues.put(COLUMN_NICKNAME, "启小航AZRgtD");
        adminValues.put(COLUMN_USERNAME, "iqhtg8BS4");
        adminValues.put(COLUMN_PHONE, "15641637332");
        adminValues.put(COLUMN_PASSWORD, "123456");
        adminValues.put(COLUMN_GENDER, "未设置");
        adminValues.put(COLUMN_EXAM_INTENTION, "四六级");
        adminValues.put(COLUMN_AVATAR_PATH, "default_avatar");  // 默认头像路径
        
        // 插入管理员数据
        db.insert(TABLE_USERS, null, adminValues);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // 如果需要升级数据库，可以在这里处理
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
        onCreate(db);
    }
} 